package com.cvs.service.impl;

import com.cvs.bean.Level;
import com.cvs.bean.Sign;
import com.cvs.dao.LevelMapper;
import com.cvs.dao.SignMapper;
import com.cvs.service.LevelService;
import com.cvs.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("signService")
public class SignServiceimpl implements SignService {

@Autowired
private SignMapper signMapper;
    @Override
    public int addSign(Sign sign) {

        if (signMapper.getSign(sign.getUid()) > 0) {
            return -1;
        } else {
            return signMapper.addSign(sign);
        }
    }

    @Override
    public List<Sign> signDay(Integer uid) {
        return signMapper.signDay(uid);
    }

    @Override
    public int signCount(Integer uid) {
        List<Sign> signs=signMapper.signDay(uid);
        int sday=0;
        int count=0;
        for (Sign sign:signs) {

            if(sday==0){
                sday=sign.getDay();
                count=1;
            }else{
                if(sday+1==sign.getDay()){
                    sday=sign.getDay();
                    count=count+1;
                }else{
                    sday=sign.getDay();
                    count=1;

                }
            }


        }
        return count;
    }
}

